package com.example.onlinereadingsystem.demos.web.controller.web;

import com.example.onlinereadingsystem.demos.web.dto.request.*;
import com.example.onlinereadingsystem.demos.web.dto.vo.GetNovelChildCommentsItemVo;
import com.example.onlinereadingsystem.demos.web.dto.vo.GetNovelChildCommentsVo;
import com.example.onlinereadingsystem.demos.web.dto.vo.GetNovelMainCommentsVo;
import com.example.onlinereadingsystem.demos.web.dto.vo.NovelReadingDetailVo;
import com.example.onlinereadingsystem.demos.web.service.NovelDetailService;
import com.example.onlinereadingsystem.demos.web.util.JwtTokenUtil;
import com.example.onlinereadingsystem.demos.web.util.Result;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description 小说详情页接口
 * @Author ljm
 * @Date 2024/12/11
 */
@RestController
@RequestMapping("/web/novelDetail")
public class NovelDetailController {
    @Autowired
    private NovelDetailService novelDetailService;

    /**
     * @param id 小说id
     * @auther ljm
     * @create 2024/11/7
     * @describe 根据id获取小说详情
     */
    @GetMapping("/getNovelReadingDetail/{id}")
    public Result<NovelReadingDetailVo> getNovelReadingDetail(@PathVariable("id") String id, HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
//        String userId = "";
//        if (!Strings.isEmpty(token)) {
//            userId = JwtTokenUtil.parseJwt(token).get("userId").toString();
//        }
        return novelDetailService.getNovelReadingDetail(id, token);
    }

    /**
     * @auther ljm
     * @create 2024/11/12
     * @describe 加入书架接口
     */
    @PostMapping("/addNovel")
    public Result<Boolean> addNovel(@RequestBody AddNovelParam param) {
        return novelDetailService.addNovel(param);
    }

    /**
     * @auther ljm
     * @create 2024/11/12
     * @describe 移除书架接口
     */
    @DeleteMapping("/removeNovel")
    public Result<Boolean> removeNovel(@RequestBody RemoveNovelParam param) {
        return novelDetailService.removeNovel(param);
    }

    /**
     * @auther ljm
     * @create 2024/12/11
     * @describe 获取小说主评论接口
     */
    @GetMapping("/getNovelMainComments")
    public Result<GetNovelMainCommentsVo> getNovelMainComments(GetNovelMainCommentsParam param) {
        return novelDetailService.getNovelMainComments(param);
    }

    /**
     * @auther ljm
     * @create 2024/12/11
     * @describe 获取小说子评论接口
     */
    @GetMapping("/getNovelChildComments")
    public Result<GetNovelChildCommentsVo> getNovelChildComments(GetNovelChildCommentsParam param) {
        return novelDetailService.getNovelChildComments(param);
    }

    /**
     * @auther ljm
     * @create 2024/12/11
     * @describe 发表评论接口
     */
    @PostMapping("/saveComments")
    public Result<Boolean> saveComments(@RequestBody SaveCommentsParam param) {
        return novelDetailService.saveComments(param);
    }
}
